<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$item=$this->plugin_setting('basic');
$return['banner']=$item['image'];
$return['setting']=$item;
if($_RQ['groupid']){
	$this->session('groupid',intval($_RQ['groupid']));
}
if($_RQ['op']=='list'){
	$return['list']=array();
	$return['groups']=pdo_getall('jy_cmsphoto_classify',array('uniacid'=>$_SESSION['uniacid'],'status'=>1));
	$return['sharedata']=array(
		'title'=>$return['setting']['share_title']?:'相册列表',
		'desc'=>$return['setting']['share_desc']?:'相册详情',
		'link'=>custom_url('jy_cmsphoto/photo/',true),
		'imgUrl'=>tomedia($return['setting']['share_image']),
	);
	exi($return);
}
if($_RQ['op']=='getlist'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
	if($this->session('groupid')){
		$params['cid']=$this->session('groupid');
	}
	if($_RQ['keyword']){
		$params['title like']='%'.trim($_RQ['keyword']).'%';
	}
    $orderby='paixu asc';
	$total='';
	$return['list']=pdo_getslice('jy_cmsphoto_photo',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	foreach($return['list'] as &$item){
		$item['url']=custom_url('jy_cmsphoto/photo/detail/id='.$item['id'],true);
		$photo=pdo_get('jy_cmsphoto_photo',array('id'=>$item['id']),array('images','title'));
		$photo['images']=json_decode($photo['images'],true);
		$item['picsnum']= count($photo['images']);
	}
	exi($return);
}
if($_RQ['op']=='detail'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请选择相册','error','jy_cmsphoto/photo/');
	}
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'id'=>$id);
	if($_RQ['keyword']){
		$params['title like']='%'.trim($_RQ['keyword']).'%';
	}
	$photo=pdo_get('jy_cmsphoto_photo',$params,array('images','audio','title'));
	$photo['images']=$photo['images']?json_decode($photo['images'],true):array();
	$return['list']=$photo['images'];
	$return['photo']=$photo;
	$return['sharedata']=array(
		'title'=>$photo['title']?$photo['title']:'相册详情',
		'desc'=>$photo['remark']?$photo['remark']:'相册说明',
		'link'=>custom_url('jy_cmsphoto/photo/detail/id='.$id,true),
		'imgUrl'=>tomedia($photo['images'][0]),
	);
	set_html('title',$photo['title']);
	exi($return);
}
?>